<template>
  <viDialog
    :deptShow="true"
    :yearShow="true"
    :monthShow="true"
    :deptList="deptList"
    :visibility.sync="visibility"
    :title="`${month}月业务进展`"
    unit="万元"
    :projectShow="true"
    @changeYear="changeYear"
    @changeMonth="changeMonth"
    @changeDept="changeDept"
    @changeProject="changeProject"
  >
    <div class="content-body">
      <viProgress ref="progress" :showHeader="true" height="300px" />
    </div>
  </viDialog>
</template>

<script>
import { viDialog, viProgress } from "@/components/visualization/index";
import request from "@/utils/request";
import Qs from "qs";
export default {
  name: "vi-popup-progress",
  components: {
    viDialog,
    viProgress,
  },
  props: {
    deptList: {
      default: () => [],
    },
  },
  data() {
    return {
      visibility: false,
      deptId: -1,
      month: "",
      year: "",
      projectId: null,
    };
  },
  created() {
    this.gettimes();
  },
  methods: {
    changeProject(val) {
      this.projectId = val;
      this.screenSpeedList();
    },
    gettimes() {
      const time = new Date();
      const year = time.getFullYear();
      const month = time.getMonth() + 1;
      const day = time.getDate();
      this.month=month
      this.year=`${year}`
    },
    changeYear(val) {
      this.year = val;
      this.screenSpeedList();
    },
    changeMonth(val) {
      this.month = val;
      this.screenSpeedList();
    },
    changeDept(val) {
      this.deptId = val;
      this.screenSpeedList();
    },
    screenSpeedList(deptId = this.deptId) {
      request({
        url: "/system/screen/speedList",
        method: "post",
        headers: { "content-type": "application/x-www-form-urlencoded" },
        data: Qs.stringify({
          deptId,
          year: this.year,
          month: this.month,
          projectId: this.projectId,
        }),
      }).then((res) => {
        const data = [];
        if (res && res.data && res.data.length > 0) {
          // 1灰色圆圈 2激活色圆圈 3有背景色条纹
          // ["申请 type1", "外证 type2", "交税 type3", "开票 type4", "抵扣 type5"]
          res.data.forEach((item) => {
            const deptName = item.deptName;
            const infos = {
              type1: 1,
              type2: 1,
              type3: 1,
              type4: 1,
              type5: 1,
            };
            if (item.infos && item.infos.length > 0) {
              item.infos.forEach((el) => {
                if (el.speedName === "申请") {
                  if (el.speedAgreeDate) {
                    infos.type1 = 2;
                  }
                  if (el.speedAgreeDate && el.speedSubmitDate) {
                    infos.type1 = 3;
                  }
                } else if (el.speedName === "外证") {
                  if (el.speedAgreeDate) {
                    infos.type2 = 2;
                  }
                  if (el.speedAgreeDate && el.speedSubmitDate) {
                    infos.type2 = 3;
                  }
                } else if (el.speedName === "交税") {
                  if (el.speedAgreeDate) {
                    infos.type3 = 2;
                  }
                  if (el.speedAgreeDate && el.speedSubmitDate) {
                    infos.type3 = 3;
                  }
                } else if (el.speedName === "开票") {
                  if (el.speedAgreeDate) {
                    infos.type4 = 2;
                  }
                  if (el.speedAgreeDate && el.speedSubmitDate) {
                    infos.type4 = 3;
                  }
                } else if (el.speedName === "抵扣") {
                  if (el.speedAgreeDate) {
                    infos.type5 = 2;
                  }
                  if (el.speedAgreeDate && el.speedSubmitDate) {
                    infos.type5 = 3;
                  }
                }
              });
            }
            data.push({
              deptName,
              infos,
            });
          });
        }
        console.log(data);
        this.$refs.progress.open(data);
      });
    },
    open() {
      this.visibility = true;
      this.screenSpeedList();
    },
  },
};
</script>

<style scoped lang="scss"></style>
